<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateRoleMenuTable extends AbstractMigration
{
    public function change(): void
    {
        $table = $this->table('role_menu', [
            'id' => true,
            'primary_key' => ['id'],
            'comment' => '角色菜单关联表',
            'engine' => 'InnoDB',
            'encoding' => 'utf8mb4',
        ]);
        $table->addColumn('role_id', 'integer', [
            'null' => false,
            'comment' => '角色ID',
        ])->addColumn('menu_id', 'integer', [
            'null' => false,
            'comment' => '菜单ID',
        ])->addColumn('create_time', 'timestamp', [
            'default' => 'CURRENT_TIMESTAMP',
            'comment' => '创建时间',
        ])->addIndex(['role_id'], [
            'name' => 'idx_role_id',
        ])->addIndex(['menu_id'], [
            'name' => 'idx_menu_id',
        ])->addIndex([
            'role_id',
            'menu_id',
        ], [
            'name' => 'uk_role_menu',
            'unique' => true,
        ])->create();
    }
}
